home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 October: Mac OS SDK / Dev.CD Oct 96 SDK / Dev.CD Oct 96 SDK2.toast / Development Kits (Disc 2) / OpenDoc Development Framework / ODFDev / ODF / Found / FWODExce / Sources / FWODExce.cpp next >
Encoding:
Text File  |  1996-08-16  |  5.7 KB  |  196 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                FWODExce.cpp
  4. //    Release Version:    $ ODF 1 $
  5. //
  6. //    Copyright:    (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #include "FWFound.hpp"
  11.  
  12. #ifndef _ERRORDEF_
  13. #include "ErrorDef.xh"
  14. #endif
  15.  
  16. #ifndef FWODEXCE_H
  17. #include "FWODExce.h"
  18. #endif
  19.  
  20. #ifndef FWPRIDEB_H
  21. #include "FWPriDeb.h"
  22. #endif
  23.  
  24. #ifndef SOM_Module_OpenDoc_Global_TypesB_defined
  25. #include "ODTypesB.xh"
  26. #endif
  27.  
  28. #include <new.h>
  29.  
  30. #if defined(__MWERKS__) && GENERATING68K
  31. // A hack to work around a bug
  32. #pragma import list somExceptionId,somExceptionValue,somSetException,somExceptionFree
  33. #endif
  34.  
  35. //========================================================================================
  36. //    Runtime Informations
  37. //========================================================================================
  38.  
  39. #ifdef FW_BUILD_MAC    
  40. #pragma segment slexcept
  41. #endif
  42.  
  43. //========================================================================================
  44. // Global functions
  45. //========================================================================================
  46.  
  47. //----------------------------------------------------------------------------------------
  48. //    FW_FailOnError
  49. //----------------------------------------------------------------------------------------
  50.  
  51. void FW_FailOnError(FW_PlatformError error)
  52. {
  53.     if (error != 0)
  54.         FW_THROW(FW_XException(error));
  55. }
  56.  
  57. //----------------------------------------------------------------------------------------
  58. //    FW_Failure
  59. //----------------------------------------------------------------------------------------
  60.  
  61. void FW_Failure(FW_PlatformError error)
  62. {
  63.     FW_ASSERT(error != 0);
  64.     FW_THROW(FW_XException(error));
  65. }
  66.  
  67. //----------------------------------------------------------------------------------------
  68. // FW_FailODError
  69. //----------------------------------------------------------------------------------------
  70.  
  71. void FW_FailOnEvError(Environment* ev)
  72. {
  73.     FW_PlatformError theError = FW_GetEvError(ev);
  74.     if (theError != FW_xNoError)
  75.     {
  76.         FW_SetEvError(ev, FW_xNoError);
  77.         FW_THROW(FW_XException(theError));
  78.     }    
  79. }
  80.  
  81. //----------------------------------------------------------------------------------------
  82. // FW_SetException
  83. //----------------------------------------------------------------------------------------
  84.  
  85. void FW_SetException(Environment *ev, const FW_XException& exception)
  86. {
  87.     FW_SetEvError(ev, exception.GetPlatformError());
  88. }
  89.  
  90. //----------------------------------------------------------------------------------------
  91. // FW_SetODException
  92. //----------------------------------------------------------------------------------------
  93.  
  94. void FW_SetEvError(Environment* ev, FW_PlatformError error)
  95. {
  96.     if (error)
  97.     {
  98.         ODException *x = (ODException*) SOMMalloc(sizeof(ODException));
  99.         x->error = error;
  100.         x->message[0] = '\0';
  101.         somSetException(ev, USER_EXCEPTION, ex_ODException, x);
  102.     }
  103.     else if (ev->_major != NO_EXCEPTION)
  104.     {
  105.         somExceptionFree(ev);
  106.         ev->_major = NO_EXCEPTION;
  107.     }
  108. }
  109.  
  110. //----------------------------------------------------------------------------------------
  111. // FW_GetODException
  112. //----------------------------------------------------------------------------------------
  113.  
  114. FW_PlatformError FW_GetEvError(Environment* ev)
  115. {
  116.     if (ev->_major)
  117.     {
  118.         const char *excpName = somExceptionId(ev);
  119.         if (FW_PrimitiveStringEqual(excpName, ex_ODException) == 1)
  120.         {
  121.             ODException *x = (ODException*) somExceptionValue(ev);
  122.             return x->error;
  123.         }
  124.         else
  125.         {
  126.             // Don't know what to do, its a non-OpenDoc error
  127.             FW_DEBUG_MESSAGE("Environment has non-OpenDoc error");
  128.             return FW_xUnknownError;
  129.         }
  130.     }
  131.     else
  132.         return FW_xNoError;
  133. }
  134.  
  135. //========================================================================================
  136. // CLASS FW_XException
  137. //========================================================================================
  138.  
  139. FW_DEFINE_CLASS_M0(FW_XException)
  140. FW_DEFINE_EXCEPTION(FW_XException)
  141.  
  142. //----------------------------------------------------------------------------------------
  143. //    FW_XException::FW_XException
  144. //----------------------------------------------------------------------------------------
  145.  
  146. FW_XException::FW_XException(const FW_XException& exception) :
  147.     fPlatformError(exception.fPlatformError)
  148. {
  149.     FW_ASSERT(fPlatformError != 0);
  150. }
  151.  
  152. //----------------------------------------------------------------------------------------
  153. //    FW_XException::FW_XException
  154. //----------------------------------------------------------------------------------------
  155.  
  156. FW_XException::FW_XException(FW_PlatformError theError) :
  157.     fPlatformError(theError == 0 ? FW_xUnknownError : theError)
  158. {
  159.     FW_ASSERT(fPlatformError != 0);
  160. }
  161.  
  162. //----------------------------------------------------------------------------------------
  163. //    FW_XException::GetPlatformError
  164. //----------------------------------------------------------------------------------------
  165.  
  166. FW_PlatformError FW_XException::GetPlatformError(void) const
  167. {
  168.     return fPlatformError;
  169. }
  170.  
  171. //----------------------------------------------------------------------------------------
  172. //    FW_XException::~FW_XException
  173. //----------------------------------------------------------------------------------------
  174.  
  175. FW_XException::~FW_XException()
  176. {
  177. }
  178.  
  179. //========================================================================================
  180. // CLASS FW_CPrivInstallNewHandler
  181. //========================================================================================
  182.  
  183. static void FW_PrivNewHandler(void)
  184. {
  185.     FW_FailOnError(kODErrOutOfMemory);
  186. }
  187.  
  188. class FW_CPrivInstallNewHandler
  189. {
  190. public:
  191.     FW_CPrivInstallNewHandler() { ::set_new_handler(FW_PrivNewHandler); }
  192.     ~FW_CPrivInstallNewHandler() {}
  193. };
  194.  
  195. FW_CPrivInstallNewHandler gInstallNewHandler;
  196.